<template>
  <div class='container'>
  <el-card>
  <el-form label-width="80px" :inline="true" size="small">
  <el-row>
    <el-col :span="18">
      <el-form-item label="查关键字">
        <el-input style="200px"
        placeholder="请输入查询内容"
        prefix-icon="el-icon-search"
        v-model="requestParams.keyword"
        >
        </el-input>
      </el-form-item>

    <el-form-item style="text-align:right">
     <el-button icon="el-icon-thumb" type="primary" @click="onSearch">查询</el-button>
    <el-button icon="el-icon-delete" type="danger"  @click="empty">清除</el-button>
  </el-form-item>
  </el-col>
    <el-col :span="6" style="text-align:right">
  <el-popover
    placement="bottom"
    title="感谢你的捐赠❤️"
    width="200"
    trigger="click">
    <!-- <el-button  slot="reference" plain>
    </el-button> -->
  <el-button type="text"  slot="reference" plain> ㅤ ㅤ</el-button>
<el-image fit="contain" :src="require('@/assets/imgs/001.jpg')"></el-image>
  </el-popover>
  <el-button  type="danger"  @click="delremoves" size="small">一键删除</el-button>
        </el-col>
</el-row>

<!-- <el-skeleton :rows="1" animated >22222</el-skeleton> -->
    <el-alert
        :title="`数据一共 ${total} 条`"
        style="margin-bottom:15px"
        type="info"
        class="alert"
        :closable="false"
        show-icon
      ></el-alert>
<!-- 列表 !!!!! -->
  <el-table
    :data="tableData">

    <el-table-column prop="id" label="编号" width="220px"></el-table-column>
    <el-table-column prop="题型" label="题型" width="80px">
      <template slot-scope="scope">
        {{questionType.find(item=>item.value===+scope.row.questionType).label}}
      </template>
    </el-table-column>
    <el-table-column prop="题目编号" label="题目编号" width="220px">
      <template slot-scope="scope">
        <div v-for="item in scope.row.questionIDs"  :key="item.number">
           <a href="#" @click.prevent="openGi(item)" style="color:#09f;">{{item.number}}</a>
        </div>
      </template>
    </el-table-column>

    <el-table-column
      label="录入时间" width="180">
      <template slot-scope="scope">
       {{scope.row.addTime}}
      </template>
    </el-table-column>
    <el-table-column prop="totalSeconds" label="答题时间(s)"></el-table-column>
    <el-table-column prop="accuracyRate" label="正确率(%)"></el-table-column>
    <el-table-column prop="userName" label="录入人"></el-table-column>
  <!-- 操作 -->
    <el-table-column label="操作">
      <template slot-scope="scope">
        <el-button
        type="danger"
        icon="el-icon-delete"
        circle
        @click="delDelete(scope.row)" title="删除">
        </el-button>
      </template>
    </el-table-column>
  </el-table>
  <!-- 分页 -->
       <el-pagination
       background
       style="margin-top:20px;text-align:right"
       layout="prev, pager, next, sizes, jumper"
       @size-change="handleSizeChange"
       @current-change="pager"
       :current-page="requestParams.page"
       :page-sizes="[20,30,50,100]"
       :page-size="requestParams.pagesize"
       :total="total">
    </el-pagination>
</el-form>
</el-card>

<!--  预览 -->
<questions-preview ref="closePreview" :dialogVisible.sync="dialogVisible" :questionInfo="questionInfo"></questions-preview>
  </div>

</template>

<script>
import { questionType } from '@/api/hmmm/constants.js'
import { randoms, removeRandoms } from '@/api/hmmm/questions.js'
import questionsPreview from '../components/questions-preview.vue'
export default {
  components: { questionsPreview },
  data () {
    return {
      // 赞助按钮
      visible: false,
      url: ('@/assets/imgs/001.jpg'),
      questionInfo: {},
      questionType,
      // difficulty,
      total: 0,
      // 列表数据
      tableData: [],
      requestParams: {
        keyword: null,
        page: 1,
        pagesize: 20
      },
      dialogVisible: false
    }
  },
  async created () {
    this.getQuest()
  },
  methods: {
    // open () {
    //   this.$prompt('答对有神秘奖励！！！', '提示', {
    //     confirmButtonText: '确定',
    //     cancelButtonText: '取消'
    //   }).then(({ value }) => {
    //     this.$message({
    //       type: 'success',
    //       message: '恭喜获得大奖: ' + value
    //     })
    //   })
    // },
    openGi (questionInfo) {
      this.dialogVisible = true
      this.questionInfo = questionInfo
      this.$nextTick(() => {
        this.$refs.closePreview.getDetail()
      })
    },
    // 组题列表
    async getQuest () {
      const { data } = await randoms(this.requestParams)
      // console.log(res)
      this.tableData = data.items
      this.total = data.counts
    },
    // 分页
    handleSizeChange (size) {
      this.requestParams.page = 1
      this.requestParams.pagesize = size
      this.getQuest()
    },
    // 分页
    pager (np) {
      this.requestParams.page = np
      this.getQuest()
    },
    /// 搜索
    onSearch () {
      this.requestParams.page = 1
      this.getQuest()
    },
    /// 搜索清空
    empty () {
      this.requestParams.keyword = null
      this.getQuest()
    },
    /// 删除
    async delDelete (question) {
      await this.$confirm('此操作将永久删除，是否继续？')
      await removeRandoms({ id: question.id })
      this.$message.success('删除成功')
      this.getQuest()
    },
    // 一键清空
    delremoves () {
      this.tableData = []
      this.requestParams.keyword = null
    }

  }
}
</script>

<style lang='scss'>
.container{
  padding: 0 10px;
  margin: 10px 0;
}
.form_itemone{
  color: Transparent;
}
.btn_wrapper {
  margin-bottom: 15px;
}
</style>
